<template>
  <DataList 
  :cate="cate" 
  :cols="cols" 
  :name="name"
  :excelHeader="excelHeader"
  :groupCheck = "groupCheck" 
 ref="datalist"
  skipExcelNumber="4"/>
</template>
<script>
import DataList from "@/components/DataList";
import { getUser } from "@/utils/auth";
import {get开设专业} from  "@/api/开设专业";
import { addCxhz, deleteCxhz, updateCxhz, getCxhz, bulkAddCxhz } from "@/api/产学合作.js";
import {findComponent} from "@/utils/ui";
import linq from "linq"
export default {
  components: {
    DataList
  },
  data() {
    return {
      cate: "A7-5产学合作表",
      name: "7.5.1 产学合作基本情况",
      excelHeader:{B3:"专业所属系部代码",C3:"专业所属系部名称",D3:"专业代码",E3:"专业名称（全称）",F3:"专业方向代码",G3:"专业方向名称（全称）",H3:"产学合作企业总数（个）",I3:"订单培养数（人）",J3:"共同开发课程数（门）",K3:"共同开发教材数（种）",L3:"支持学校兼职教师数（人）",M3:"接受顶岗实习学生数（人）",N3:"对学校捐赠设备总值（万元）",O3:"对学校准捐赠设备总值（万元）",P3:"接受毕业生就业数（人）",Q3:"学校为企业技术服务年收入（万元）",R3:"学校为企业年培训员工数（人天）",S3:"主要合作企业",S4:"企业一",U4:"企业二",W4:"企业三",Y4:"企业四",AA4:"企业五",S5:"企业名称(全称)",T5:"合作开始日期（年月）",U5:"企业名称(全称)",V5:"合作开始日期（年月）",W5:"企业名称(全称)",X5:"合作开始日期（年月）",Y5:"企业名称(全称)",Z5:"合作开始日期（年月）",AA5:"企业名称(全称)",AB5:"合作开始日期（年月）",AC3:"是否合作开展学徒制专业"},

      cols: [
        { label: "专业所属系部代码", prop: "BMBH" },
        { label: "专业所属系部名称", prop: "BMMC" },
        { label: "专业代码", prop: "ZYDM" },
        { label: "专业名称(全称)", prop: "ZYMC" },
        { label: "专业方向代码", prop: "ZYFXDM" },
        { label: "专业方向名称(全称)", prop: "ZYFXMC" },
        { label: "产学合作企业总数(个)", prop: "CXHZQYZS" },
        { label: "订单培养数(人)", prop: "DDPYRS" },
        { label: "共同开发课程数(门)", prop: "GTKFKCMS" },
        { label: "共同开发教材数(种)", prop: "GTKFJCS" },
        { label: "支持学校兼职教师数(人)", prop: "ZCXXJZJSS" },
        { label: "接受顶岗实习学生数(人)", prop: "JSDGSXXSS"},
        { label: "对学校捐赠设备总值(万元)", prop: "DXXJZSBZE" },
        { label: "对学校准捐赠设备总值(万元)", prop: "DXXZJZSBZZ" },
        { label: "接受毕业生就业数(人)", prop: "JSBYSJYS" },
        { label: "学校为企业技术服务年收入(万元)", prop: "XXWQYJSFWNSR" },
        { label: "学校为企业年培训员工数(人天)", prop: "XXWQYNPXYGS" },
        {label: "主要合作企业",data:[
          {label: "企业一",data:[
            {label: "企业名称(全称)",prop:"HZQYMC1"},
            {label: "合作开始日期(年月)",prop:"HZKSNY1"}
          ]},
          {label: "企业二",data:[
            {label: "企业名称(全称)",prop:"HZQYMC2"},
            {label: "合作开始日期(年月)",prop:"HZKSNY2"}
          ]},
          {label: "企业三",data:[
            {label: "企业名称(全称)",prop:"HZQYMC3"},
            {label: "合作开始日期(年月)",prop:"HZKSNY3"}
          ]},
          {label: "企业四",data:[
            {label: "企业名称(全称)",prop:"HZQYMC4"},
            {label: "合作开始日期(年月)",prop:"HZKSNY4"}
          ]},
          {label: "企业五",data:[
            {label: "企业名称(全称)",prop:"HZQYMC5"},
            {label: "合作开始日期(年月)",prop:"HZKSNY5"}
          ]}
        ]},
        {label:"是否合作开展学徒制专业",prop:"XZ_SFXTZZY"}
      ],
      
       groupCheck:[{data:["HZQYMC1","HZKSNY1"],desc:'请完善企业一的输入'},
         {data:["HZQYMC2","HZQYMC2"],desc:'请完善企业二的输入'},
         {data:["HZQYMC3","HZQYMC3"],desc:'请完善企业三的输入'},
         {data:["HZQYMC4","HZQYMC4"],desc:'请完善企业四的输入'},
         {data:["HZQYMC5","HZQYMC5"],desc:'请完善企业五的输入'}
       ]
    };
  },
  methods: {
   getSummaries(list){
      //
        const sums = [];
         this.cols.forEach((column, index) => {
            sums[index]="";
        });
         sums[0]="合计";
         sums[6]="系部数:"+linq.from(list).distinct("$.BMBH").count()
         sums[8]="专业数:"+linq.from(list).distinct("$.ZYDM").count()
         sums[10]="方向数:"+linq.from(list).distinct("$.ZYFXDM").count()
         sums[12]=""+linq.from(list).sum("$.CXHZQYZS")
         sums[13]=""+linq.from(list).sum("$.DDPYRS")
         sums[14]=""+linq.from(list).sum("$.GTKFKCMS")
         sums[15]=""+linq.from(list).sum("$.GTKFJCS")
         sums[16]=""+linq.from(list).sum("$.ZCXXJZJSS")
         sums[17]=""+linq.from(list).sum("$.JSDGSXXSS")
         sums[18]=""+linq.from(list).sum("$.DXXJZSBZE")
         sums[19]=""+linq.from(list).sum("$.JSBYSJYS")
         sums[20]=""+linq.from(list).sum("$.XXWQYJSFWNSR")
         sums[21]=""+linq.from(list).sum("$.XXWQYNPXYGS")
         sums[33]= "专业数:"+linq.from(list).sum("$.XZ_SFXTZZY == '是'")
         sums[34]= "通过:"+linq.from(list).where("$.审核状态=='通过'").count();
         sums[34]+= ",不通过:"+linq.from(list).where("$.审核状态=='不通过'").count();
         sums[34] += ",待审核:"+linq.from(list).where("$.审核状态=='待审核'").count();
 
       return sums;
      //
    },
    async  onDlgCreated(model) {
            var dd = findComponent(this,"ZYFXMC");
          var ZYFXMC = linq.from( this.$root.开设专业).distinct("$.ZYFXMC").toArray();
        
          dd.$attrs.items = ZYFXMC.map(item => {
            return { label: item.ZYFXMC, value: item.ZYFXMC};
          });
    },
    async  bulkAdd(array){
       await  bulkAddCxhz({Cxhz:array});
    },
     check(array,list) {
     return new Promise(async (resolve,reject)=>{
         try{
          var user = getUser();
          var 专业 = await get开设专业(user.XXID,user.CJPC)
          //是否已经存在相同
        
          var err =  linq.from(array).select("$.ZYDM+','+$.ZYFXDM").except(linq.from(专业).select("$.ZYDM+','+$.ZYFXDM").toArray()).toArray();
          linq.from(array).where(e=>err.indexOf(e.ZYDM+','+e.ZYFXDM) !==-1).forEach(e=>e.error=e.error?e.error+";":''+"开设专业表不存在对应的专业代码与专业方向代码组合合");
          
          //把错误的教师姓名替代掉
          err =  linq.from(array).select("$.ZYDM+','+$.ZYMC+','+$.ZYFXDM+','+$.ZYFXMC").except(linq.from(专业).select("$.ZYDM+','+$.ZYMC+','+$.ZYFXDM+','+$.ZYFXMC").toArray()).toArray();
          linq.from(array).where(e=>err.indexOf(e.ZYDM+','+e.ZYMC+','+e.ZYFXDM+','+e.ZYFXMC) !==-1).
          forEach(e=>{
            var d = linq.from(专业).firstOrDefault(item=>item.ZYDM == e.ZYDM && item.ZYFXDM == e.ZYFXDM);
            if(d){
              e.ZYMC = d.ZYMC;
              e.ZYFXMC = d.ZYFXMC;
              e.BMMC = d.BMMC;
              e.BMBH = d.BMBH;
            }
          });
            resolve();
          }catch(e){
            reject(e);
          }
     }) 
    },
    onChange(model, field, value) {
      //
      if (field == "ZYFXMC") {
        
        var temp =  linq.from( this.$root.开设专业).first(item=>item.ZYFXMC==value);
        model.BMBH = temp.BMBH;
        model.BMMC = temp.BMMC;
        model.ZYMC = temp.ZYMC;
        model.ZYDM = temp.ZYDM;
        
        model.ZYFXDM = temp.ZYFXDM;
        
      }
      //
    },
    async fetchData() {
      var user =  getUser()
      var datas = await getCxhz(user.XXID,user.CJPC);
      return datas;
    },
    onadd(model) {
      //
      var temp = JSON.parse(JSON.stringify(model))
      return new Promise(async (resolve,reject)=>{
           
          console.log(JSON.stringify(temp));
          var model = await addCxhz(temp);
          resolve(model);
      })

    },
    onupdate(model) {
      //
      var temp = JSON.parse(JSON.stringify(model))
      return new Promise(async (resolve,reject)=>{
           
          console.log(JSON.stringify(temp));
          var model = await updateCxhz(temp);
          resolve(model);
      })
      //
    },
    ondelete(model) {
       var temp = JSON.parse(JSON.stringify(model))
      return new Promise(async (resolve,reject)=>{
         await deleteCxhz(temp);
          resolve();
      })
    }
  }
};
</script>
<style>
</style>